#!/bin/bash

commit_message=$(cat "$1")
regex='^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\([a-zA-Z0-9_-]+\))?: .+'

# Check if the commit message starts with "Merge branch"
if [[ $commit_message =~ ^"Merge" ]]; then
  # Exit successfully without doing anything
  exit 0
fi

# Check for semantic commit message format
if [[ ! $commit_message =~ $regex ]]; then
  echo "Commit message failed semantic commit message style."
  echo "Please follow the pattern: <type>(<scope>): <message>"
  echo "See conventional commits for more info: https://www.conventionalcommits.org/en/v1.0.0/"
  exit 1
fi
